/*
 *  JDiv - API for Multimedia Application
 *  http://jdiv.sourceforge.net 
 *  ------------------------------------
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 */

package com.jdiv.functions;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.jdiv.JDiv;
import com.jdiv.Scene;
import com.jdiv.internalClasses.JDivEffect;
import com.jdiv.kernel.JDivResources;
import com.jdiv.kernel.JDivSystem;

/**Class for loading and handling Screen Effects.*/
public class FunctionsEffects {
	
	/**
	 * Load a Effect to JDiv.
	 * @param strFileEffect File of effect.
	 * @param strDir Images directory for effect.
	 * @return Number identifier of Effect.
	 */
	
	public int load( String strFileEffect, String strDir ){
		
        FileHandle fileEffect = Gdx.files.internal(strFileEffect);
		
		if( !fileEffect.exists() ){
			JDiv.system.log("ERROR, load() - File effect not found: '" + strFileEffect + "'" );
			return 0;
		}
		
        FileHandle dir = Gdx.files.internal(strDir);
		
		if( !dir.exists() ){
			JDiv.system.log("ERROR, load() - File texture not found: '" + strDir + "'" );
			return 0;
		}
		
		return JDivResources.listEffects.effectAdd(fileEffect, dir);
	}
	
	/**
	 * Gets the Effect stored in JDiv.
	 * @param idEffect Number identifier of Effect.
	 * @return ParticleEffect from LibGdx.
	 */
	
	public ParticleEffect getParticleEffect( int idEffect ) {
        JDivEffect jdivEffect = JDivResources.listEffects.getJDivEffect(idEffect);
        
        ParticleEffect effect = null;
		
		if( jdivEffect != null )
			if( jdivEffect.isLoadEffect() )
				effect = jdivEffect.effect;
		
		if( effect == null )
			JDiv.system.log("getParticleEffect() - Before using this function must call to 'frame()' so that the load is made.");		
		
		return effect;
	}
	
	/**
	 * Sets the visibility of the effect. 
	 * @param idEffect Number identifier of Effect.
	 * @param show True is visible, and false not.
	 */
	
	public void setVisible( int idEffect, boolean show ) {
        JDivEffect effect = JDivResources.listEffects.getJDivEffect(idEffect);
		
		if( effect != null )
			if( effect.isLoadEffect() ){
				effect.show = show;
			}
	}
	
	/**
	 * Sets Depth of the effects scene, initially its value is 0.
	 * @param depth Depth of scene.
	 */
	
	public void setDepth( int depth ){
		
		if( JDivSystem.effectsScene != null )
			JDivSystem.effectsScene.setDepth(depth);
		
	}
	
	/**
	 * @return Depth of scene.
	 */
	
	public int getDepth(){
		if( JDivSystem.effectsScene != null )
			return JDivSystem.effectsScene.getDepth();
		
		return 0;
	}
	
	/**
	 * Gets the effects scene.
	 * @return Effects Scene.
	 */
	
	public Scene getScene(){
		return JDivSystem.effectsScene;
	}
	
	/**
	 * Unload Effect stored in JDiv. Be careful when using this function, if you unload the effect can no longer be reused.
	 * @param idEffect Number identifier of Effect.
	 */
	
	public void unload( int idEffect ){
		JDivResources.listEffects.effectDipose(idEffect);
	}

}
